﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlatRedBall.Math.Geometry;
using FlatRedBall;
using FlatRedBall.Input;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using FlatRedBall.Math;
using TopDownShooter.Screens;

namespace TopDownShooter
{
    class Player : Unit
    {
        public Player(GameScreen screen)
            : base(screen)
        {
            Camera = SpriteManager.Camera;
            Camera.AttachTo(this, false);
            Camera.ParentRotationChangesRotation = false;
            Camera.RelativeZ = 100;
        }
        internal void onBulletCollide(Bullet bullet)
        {
            Health -= bullet.Damage;
            bullet.Destroy();
        }
        public new void Activity()
        {
            Vector2 movementVector = Vector2.Zero;
            // Controls
            if (InputManager.Keyboard.KeyDown(Keys.W))
                movementVector.Y++;
            if (InputManager.Keyboard.KeyDown(Keys.D))
                movementVector.X++;
            if (InputManager.Keyboard.KeyDown(Keys.S))
                movementVector.Y--;
            if (InputManager.Keyboard.KeyDown(Keys.A))
                movementVector.X--;
            // Weapon selection
            if (InputManager.Keyboard.KeyPushed(Keys.D1))
            {
                SelectWeapon(pistol);
            }
            if (InputManager.Keyboard.KeyPushed(Keys.D2))
            {
                SelectWeapon(smg);
            }
            if (InputManager.Keyboard.KeyPushed(Keys.D3))
            {
                SelectWeapon(shotgun);
            }



            if (InputManager.Keyboard.KeyPushed(Keys.R) && weapon.bulletsCurrentlyInClip != weapon.clipSize)
                weapon.reloading = true;
            weapon.DoMouseInput();
            
            if (!(movementVector.X == 0 && movementVector.Y == 0))
            {
                movementVector.Normalize();
                X += movementVector.X * speed;
                Y += movementVector.Y * speed;
            }
            foreach (Bullet b in bulletsFired)
                b.Activity();
            weapon.Activity();
            healthBar.SetHealth(Health);
            if (Health <= 0)
            {
                Screen.playerDeath();
                this.Destroy();
            }

        }
    }
}
